package com.beiing.tianshuai.tianshuai.huodong.model;

import android.util.Log;

import com.beiing.tianshuai.tianshuai.dongtai.CallBack;
import com.beiing.tianshuai.tianshuai.entity.ActiveReplyBean;
import com.beiing.tianshuai.tianshuai.entity.CodeBean;
import com.beiing.tianshuai.tianshuai.entity.DynamicDeleteBean;
import com.beiing.tianshuai.tianshuai.entity.FollowBean;
import com.beiing.tianshuai.tianshuai.entity.FollowResultBean;
import com.beiing.tianshuai.tianshuai.entity.HuoDongCollectBean;
import com.beiing.tianshuai.tianshuai.entity.HuoDongCommentBean;
import com.beiing.tianshuai.tianshuai.entity.HuoDongDetailBean;
import com.beiing.tianshuai.tianshuai.entity.HuoDongPraiseBean;
import com.beiing.tianshuai.tianshuai.network.DataManager;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by magikliu on 2017/8/6.
 */

public class HuoDongDetailModel implements HuoDongDetailModelImpl{

    private static final String TAG = "HuoDongDetailModel";

    /**
     * 获得活动详情
     *
     * @param uid
     * @param id
     * @param callBack
     */
    @Override
    public void getHuoDongDetail(String uid, String id, final CallBack callBack) {
        Log.i(TAG, "请求活动详情");
        DisposableObserver<HuoDongDetailBean> observer = new DisposableObserver<HuoDongDetailBean>() {
            @Override
            public void onNext(@NonNull HuoDongDetailBean huoDongDetailBean) {
                callBack.result(huoDongDetailBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getHuoDongDetail(uid, id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /**
     * 收藏活动
     *
     * @param uid
     * @param aid
     * @param callBack
     */
    @Override
    public void collectHuoDong(String uid, String aid, final CallBack callBack) {
        DisposableObserver<HuoDongCollectBean> observer = new DisposableObserver<HuoDongCollectBean>() {
            @Override
            public void onNext(@NonNull HuoDongCollectBean huoDongCollectBean) {
                callBack.result(huoDongCollectBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getHuoDongCollectResult(uid, aid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /**
     * 取消收藏
     *
     * @param uid
     * @param aid
     * @param callBack
     */
    @Override
    public void cancelCollect(String uid, String aid, CallBack callBack) {

    }

    /**
     * 评论活动
     *
     * @param aid
     * @param uid
     * @param content
     * @param add_time
     * @param callBack
     */
    @Override
    public void commentHuoDong(String aid, String uid, String content, String add_time, final CallBack callBack) {
        DisposableObserver<HuoDongCommentBean> observer = new DisposableObserver<HuoDongCommentBean>() {
            @Override
            public void onNext(@NonNull HuoDongCommentBean huoDongCommentBean) {
                callBack.result(huoDongCommentBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getHuoDongCommentResult(aid, uid, content, add_time)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void attentionUser(String form_uid, String to_uid, final CallBack callBack) {
        DisposableObserver<FollowResultBean> observer = new DisposableObserver<FollowResultBean>() {
            @Override
            public void onNext(@NonNull FollowResultBean followResultBean) {
                callBack.result(followResultBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };

        DataManager.getFollowResult(form_uid, to_uid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void isFollowed(String fromUid, String toUid, final CallBack callBack) {
        DisposableObserver<FollowBean> observer = new DisposableObserver<FollowBean>() {
            @Override
            public void onNext(@NonNull FollowBean followBean) {
                callBack.result(followBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.isFollowed(fromUid, toUid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void setFollowed(String fromUid, String toUid, final CallBack callBack) {
        DisposableObserver<FollowResultBean> observer = new DisposableObserver<FollowResultBean>() {
            @Override
            public void onNext(@NonNull FollowResultBean followResultBean) {
                callBack.result(followResultBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getFollowResult(fromUid, toUid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void praiseHuoDong(String userid, String aid, final CallBack callBack) {
        DisposableObserver<HuoDongPraiseBean> observer = new DisposableObserver<HuoDongPraiseBean>() {
            @Override
            public void onNext(@NonNull HuoDongPraiseBean huoDongPraiseBean) {
                callBack.result(huoDongPraiseBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getHuoDongPraiseResult(userid, aid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void praiseComment(String uid, String cid, final CallBack callBack) {
        DisposableObserver<HuoDongPraiseBean> observer = new DisposableObserver<HuoDongPraiseBean>() {
            @Override
            public void onNext(@NonNull HuoDongPraiseBean bean) {
                callBack.result(bean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getActiveCommentPraiseResult(uid, cid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void deleteComment(String id, final CallBack callBack) {
        DisposableObserver<CodeBean> observer = new DisposableObserver<CodeBean>() {
            @Override
            public void onNext(CodeBean codeBean) {
                callBack.result(codeBean);
            }

            @Override
            public void onError(Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };

        DataManager.getActiveCommentDelResult(id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void addReply(String aid, String cid, String form_id, String to_id, String content, String comment, int type, String rid, final CallBack callBack) {
        DisposableObserver<ActiveReplyBean> observer = new DisposableObserver<ActiveReplyBean>() {
            @Override
            public void onNext(ActiveReplyBean activeReplyBean) {
                callBack.result(activeReplyBean);
            }

            @Override
            public void onError(Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };

        DataManager.getActiveReplyResult(aid, cid, form_id, to_id, content, comment, type, rid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void deleteReply(String aid, String id, String uid, final CallBack callBack) {
        DisposableObserver<DynamicDeleteBean> observer = new DisposableObserver<DynamicDeleteBean>() {
            @Override
            public void onNext(DynamicDeleteBean deleteBean) {
                callBack.result(deleteBean);
            }

            @Override
            public void onError(Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getActiveReplyDeleteResult(aid, id, uid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void praiseReply(String uid, String aid, String cid, String rid, String to_uid, final CallBack callBack) {
        DisposableObserver<HuoDongPraiseBean> observer = new DisposableObserver<HuoDongPraiseBean>() {
            @Override
            public void onNext(HuoDongPraiseBean huoDongPraiseBean) {
                callBack.result(huoDongPraiseBean);
            }

            @Override
            public void onError(Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };

        DataManager.getActiveReplyPraiseResult(uid, aid, cid, rid, to_uid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }
}
